window.onload = function () {
    // 什么是解构
    // ES6 允许按照一定模式，从数组和对象中提取值，对变量进行赋值，这被称为解构（Destructuring）。
    // 解构是ES6的新特性, 比ES5代码简洁，清晰，减少代码量
    //数组解构
    // let a = 1;
    // let b = 2;
    // let c = 3;
    // let d = 4;

    //简化
    // let a = 1,b=2,c=3,d=4;

    //es6
    //let [a,b,c,d] = [1,2,3,4];

    // let color = ['red','blue','green'];
    // let [r,b,g] = color;

    //匹配不成功
    // let [a,b,c,d] = [1,2,3,4,5,6];
    // 左边模式匹配，定义变量  ，右边对应的数据

    // let [a,b,c,d] = [[1,2,3],true,{id:1},100];

    // let [x,[y1,y2],z] = [1,[2,3],4]
    // console.log(y1)//2

    let arr = [100,200];
    // if(arr[0]){
    //     var x = arr[0]
    // }else {
    //     var x = 1;
    // };
    // //简化
    // var x = arr[0] || 1;
    // //默认值
    // let [x=1] = arr;

    let [x=1,y=1] = arr;
    console.log(x,y)  //100 200
    // let x = arr[0] ||1;
    // let y = arr[1] ||1;
    //默认值什么生效？成员等于undefined，默认值才会生效

    //扩展题
    var [a=1,b=2] = [10]; //10,2
    var [a,b='y'] = ['a']; //'a','y'
    var [a=1,b] = [100,null]; //100,null
    var [a=1,b] = [undefined,null]; //1,null

    //默认值是表达式，惰性求值，只有在用到的时候，才会求值
    function f(){
        return 88
    };
    var [a = 1,b = f()] = [100,200];  //100 200  
    console.log(b) //200

    var b = 200 || f();  //惰性求值

    var [a = 1,b = f()]  = []; //1,88
    var [a = 1,b = f()]  = [undefined];  //1,88

    //特殊的情况
    var [a = 1,b = a] =[];
    console.log(a,b)  //1 1
    var [a = 1,b = a] =[2,3]; //2 3
    var [a = 1,b = a] =[2]; 
    console.log(a,b) //2 2

    var [a = b,b = 1] =[]; 
    var [a = b,b = 1] =[2]; 









}



